
package processors;

import containers.TestScores;
import readers.QueryStringHandler;
import writers.UserWriter;

/**
 * This creates a list of scores for the quizzes a student has taken
 * as the webcomponent uses a different processor this will only be
 * called by students, thus the naming
 * @author Chris
 */
public class processorQuizSetScores extends processor {
    private String _errMsg;
    processorQuizSetScores(String query) {
        super(query);
        _errMsg = "[ERROR]";
    }
    
    @Override
    String process() {
        QueryStringHandler qsh = new QueryStringHandler(_queryString);
        String userName = qsh.getElement("username");
        String teacherName = qsh.getElement("TN");
        String groupName = qsh.getElement("GN");
        String testName = qsh.getElement("TID");
        String score = qsh.getElement("score");
        
        if(userName == null || teacherName == null ||
                groupName == null || testName == null || score == null) {
            return _errMsg;
        }
        
        
        TestScores scores = new TestScores();
        scores.userName = userName;
        scores.score = Integer.parseInt(score);
        
        UserWriter.appendTestScores(teacherName, groupName, testName, scores);
        UserWriter.appendTakenTests(userName, teacherName, groupName, testName, score);
        
        return "Complete";
    }
}
